<template>
  <div style="width:1200px;margin:0 auto;background-color:#fff;border:1px solid #e0e0e0;padding:20px">
    <div style="border-bottom: 1px solid #e0e0e0;margin-top:20px;margin-bottom:20px;height:60px;">
      <img src="../images/tylogo.png"  @click="loginPage" style="vertical-align:bottom"/>
      <span style="font-size:18px;color:#323232;margin-left:10px">供应商合作申请</span> <span style="font-size:14px;color:#646464;margin-left:20px">1.提交合作申请   2.莱丹确认合作意向   3.签约合同，完成上线</span>
      <span class="loginbtn" @click="loginPage">登录</span>
    </div>
    <el-form ref="form" :model="company" :rules="registerRule" :inline="true" label-width="120px" style="margin-left:100px;">
      <h1 class="bt_t">账号基本信息</h1>
      <el-form-item label="用户名" prop="loginName" id="width200">
        <el-input v-model="company.loginName" placeholder="用户名"></el-input>
      </el-form-item>
      <el-form-item label="真实姓名" prop="userName" id="width200">
        <el-input v-model="company.userName" placeholder="真实姓名"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password" id="width200">
        <el-input v-model="company.password" placeholder="密码" type="password"></el-input>
      </el-form-item>
      <el-form-item label="确认密码" prop="surePassword" id="width200">
        <el-input v-model="company.surePassword" placeholder="确认密码" type="password"></el-input>
      </el-form-item>
      <el-form-item label="手机号" prop="phone" id="width200">
        <el-input v-model="company.phone" placeholder="手机号"></el-input>
      </el-form-item>
      <h1 class="bt_t">供应商合作申请</h1>
      <el-form-item label="品牌名称" prop="brandName" id="width200">
        <el-input v-model="company.brandName" placeholder="品牌名称"></el-input>
      </el-form-item>
      <el-form-item label="公司名称" prop="companyName" id="width200">
        <el-input v-model="company.companyName" placeholder="公司名称"></el-input>
      </el-form-item>
      <el-form-item label="合作类型" prop="industryType">
        <el-checkbox-group
          v-model="checkedIndustryTypes"  @change="handleIndustryTypeChecked">
          <el-checkbox v-for="(item, index) in industryTypeStr" :label="item.value" :key="item.value">{{ item.label }}</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
      <el-form-item label="企业地址" prop="city">
        <div class="block" id="fontsize">
          <kt-distpicker :placeholders="placeholders"
                        :province="company.province" :city="company.city" :area="company.county"
                        @selected="citySelected">
          </kt-distpicker>
        </div>
      </el-form-item>
      <div>
        <el-form-item label="详细地址" prop="address">
          <el-input v-model="company.address" placeholder="详细地址" style="width:692px;"></el-input>
        </el-form-item>
      </div>
      <el-form-item label="邮编" prop="postcode" id="width200">
        <el-input v-model="company.postcode" placeholder="邮编"></el-input>
      </el-form-item>
      <el-form-item label="企业电话" prop="companyTel" id="width200">
        <el-input v-model="company.companyTel" placeholder="企业电话"></el-input>
      </el-form-item>
      <el-form-item label="注册资金" prop="registeredCapital" id="width200">
        <el-input v-model="company.registeredCapital" placeholder="注册资金"></el-input>
      </el-form-item>
      <el-form-item label="注册时间" prop="registeredDate" id="width200">
        <el-date-picker type="date" placeholder="注册时间" :editable="false" v-model="company.registeredDate" style="width: 100%;"></el-date-picker>
      </el-form-item>
      <h1 class="bt_t">联系人信息</h1>
      <el-form-item label="联系人姓名" prop="linkMan" id="width200">
        <el-input placeholder="联系人姓名" v-model="company.linkMan"></el-input>
      </el-form-item>
      <el-form-item label="联系人手机" prop="linkPhone" id="width200">
        <el-input v-model="company.linkPhone" placeholder="联系人手机"></el-input>
      </el-form-item>
      <el-form-item label="联系人电话" prop="linkTel" id="width200">
        <el-input v-model="company.linkTel" placeholder="联系人电话"></el-input>
      </el-form-item>
      <el-form-item label="联系人邮箱" prop="linkEmail" id="width200">
        <el-input v-model="company.linkEmail" placeholder="联系人邮箱"></el-input>
      </el-form-item>
      <el-form-item label="联系人QQ" prop="linkQQ" id="width200">
        <el-input placeholder="联系人QQ" v-model="company.linkQQ"></el-input>
      </el-form-item>
      <el-form-item label="联系人微信" prop="linkWeixin" id="width200">
        <el-input v-model="company.linkWeixin" placeholder="联系人微信"></el-input>
      </el-form-item>
    <h1 class="bt_t">企业法人/资质信息</h1>
      <el-form-item label="法人姓名" prop="legalName" id="width200">
        <el-input v-model="company.legalName" placeholder="法人姓名"></el-input>
      </el-form-item>
      <el-form-item label="法人身份证" prop="legalCardNo" id="width200">
        <el-input v-model="company.legalCardNo" placeholder="法人身份证"></el-input>
      </el-form-item>
      <el-form-item label="法人联系手机" prop="legalPhone" id="width200">
        <el-input v-model="company.legalPhone" placeholder="法人联系手机"></el-input>
      </el-form-item>
      <el-form-item label="营业执照号" prop="businessLicenseNo" id="width200">
        <el-input v-model="company.businessLicenseNo" placeholder="营业执照号"></el-input>
      </el-form-item>
      <div>
      <el-form-item label="营业执照证件" prop="bpList">
        <el-upload action="/smartLight/web/baseAccount/uploadNo.htm"
                   :data="blPicData" ref="bpUpload" accept=".jpg,.jpeg,.bmp,.gif,.png"
                   :file-list="company.bpList" :auto-upload="false"
                   :on-change="bChangeFunc"
                   :on-success="businessLicenseNoSuccess"
                   :on-remove="businessLicenseNoRemove"
                   :http-request="syncUpload"
        >
          <el-button size="small" type="primary">上传文件</el-button>
          <span scope="tip" style="color:red;">* 只能上传jpg/jpeg/bmp/gif/png文件,大小不超过5M</span>
        </el-upload>
      </el-form-item>
      </div>
      <div>
      <el-form-item label="经营许可证号" prop="licenceNo" id="width200">
        <el-input v-model="company.licenceNo" placeholder="经营许可证号"></el-input>
      </el-form-item>
      </div>
        <div>
      <el-form-item label="经营许可证" prop="lpList">
        <el-upload action="/smartLight/web/baseAccount/uploadNo.htm" :data="lPicData"
                   ref="licenceNoUpload" :auto-upload="false" accept=".jpg,.jpeg,.bmp,.gif,.png"
                   :file-list="company.lpList" class="upload-demo"
                   :on-change="licencePicChange"
                   :on-success="licencePicSuccess"
                   :on-remove="licencePicRemove"
                   :http-request="syncUpload"
        >
          <el-button size="small" type="primary">上传文件</el-button>
          <span scope="tip" style="color:red;"> * 只能上传jpg/jpeg/bmp/gif/png文件,大小不超过5M</span>
        </el-upload>
      </el-form-item>
      </div>
      <div>
      <el-form-item label="其他证明" prop="opList">
        <el-upload action="/smartLight/web/baseAccount/uploadNo.htm" :data="oPicData"
                   ref="otherUpload" :auto-upload="false" accept=".jpg,.jpeg,.bmp,.gif,.png"
                   :file-list="company.opList"
                   :on-change="otherPicChange"
                   :on-success="otherPicSuccess"
                   :on-remove="otherPicRemove"
                   :http-request="syncUpload"
        >
          <el-button size="small" type="primary">上传文件</el-button>
          <span scope="tip" style="color:red;">* 只能上传jpg/jpeg/bmp/gif/png文件,大小不超过5M</span>
        </el-upload>
      </el-form-item>
      </div>
      <el-form-item style="margin-left:400px">
        <el-button type="primary" size="large" @click="goRegister" style="margin: 20px auto; width: 200px;" :loading="subRegisterLoading">提交注册</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script type="text/ecmascript-6">
  import VDistpicker from 'v-distpicker'
  import KtDistpicker from '../base/citiesPlugin/kt-distpicker.vue'
  import $ from 'jquery'
  const industryTypes = [
    {value: 'tour', label: '旅游'},
    {value: 'visa', label: '签证'},
    {value: 'flight', label: '机票'},
    {value: 'hotel', label: '酒店'},
    {value: 'car', label: '车票'},
    {value: 'sea', label: '邮轮'},
    {value: 'ticket', label: '门票'}
  ]
  export default {
    data () {
      // 验证手机格式
      var checkPhone = (rule, value, callback) => {
        var reg = new RegExp('^1[34578]\\d{9}$')
        if (!reg.test(value)) {
          callback(new Error('手机电话格式不正确'))
        } else {
          callback()
        }
      }
      // 验证用户名
      var validateLoginName = (rule, value, callback) => {
        var teg = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？]")
        if (teg.test(value) || value.trim === '') {
          callback(new Error('请输入正确的用户名'))
        } else {
          this.$http.post('/smartLight/web/baseAccount/checkLoginName.htm', {type: this.type, loginName: this.company.loginName}).then(response => {
            var resBody = response.body
            if (resBody.isSuccess !== 0) {
              callback(new Error('用户名已注册，请重新输入'))
            } else {
              callback()
            }
          })
        }
      }
      // 验证密码
      var checkPassword = (rule, value, callback) => {
        if (value.length > 18 || value.length < 6) {
          callback(new Error('请输入6~18个字符'))
        } else {
          callback()
        }
      }
      var checkSurePassword = (rule, value, callback) => {
        if (value.length > 18 || value.length < 6) {
          callback(new Error('请输入6~18个字符'))
        } else {
          if (value !== this.company.password) {
            callback(new Error('两次密码输入不一致'))
          } else {
            callback()
          }
        }
      }
      // 验证邮箱格式
      var checkEmail = (rule, value, callback) => {
        var reg = new RegExp('^\\w+([\\.-]?\\w+)*@\\w+([\\.-]?\\w+)*(\\.\\w{2,3})+$')
        if (value === '') {
          callback()
        } else {
          if (!reg.test(value)) {
            callback(new Error('请输入正确的邮箱'))
          } else {
            callback()
          }
        }
      }
      // 验证QQ
      var checkQQ = (rule, value, callback) => {
        var reg = new RegExp('^\\d{5,10}$')
        if (value === '' || reg.test(value)) {
          callback()
        } else {
          callback(new Error('请输入正确的QQ'))
        }
      }
      // 验证身份证号码
      var checkCardNo = (rule, value, callback) => {
        this.$http.post('/smartLight/web/baseAccount/checkIDCard.htm', {cardNo: value}).then(response => {
          var resBody = response.body
          if (resBody.isSuccess !== 0) {
            callback(new Error('请输入正确的身份证号码!'))
          } else {
            callback()
          }
        })
      }
      // 邮编验证
      var checkPostcode = (rule, value, callback) => {
        var reg = new RegExp('^[1-9][0-9]{5}$')
        if (reg.test(value)) {
          callback()
        } else {
          callback(new Error('请输入正确的邮政编码'))
        }
      }
      // 验证营业执照
      var checkBNo = (rule, value, callback) => {
        var reg = new RegExp('\\d{15}')
        if (reg.test(value)) {
          callback()
        } else {
          callback(new Error('请输入正确的营业执照号码'))
        }
      }
      // 经营许可证验证
      var checkLicenceNo = (rule, value, callback) => {
        var reg = new RegExp('[A-Z]{2}[0-9]{14}')
        if (reg.test(value)) {
          callback()
        } else {
          callback(new Error('请输入正确的经营许可证号码'))
        }
      }
      // 企业联系电话验证
      var checkLinkTel = (rule, value, callback) => {
        var reg = new RegExp('^((\\d{3,4}\\-)|)\\d{7,8}(|([-\u8f6c]{1}\\d{1,5}))$')
//        var reg1 = new RegExp('^1[34578]\\d{9}$')
        if (reg.test(value) || value === '') {
          callback()
        } else {
          callback(new Error('请输入正确的电话'))
        }
      }
      // 企业电话验证
      var checkCompanyTel = (rule, value, callback) => {
        var reg = new RegExp('^((\\d{3,4}\\-)|)\\d{7,8}(|([-\u8f6c]{1}\\d{1,5}))$')
//        var reg1 = new RegExp('^1[34578]\\d{9}$')
        if (reg.test(value)) {
          callback()
        } else {
          callback(new Error('请输入正确的电话'))
        }
      }
      return {
        subRegisterLoading: false,
        placeholders: { // 省市区组件为空时的占位符
          province: '------- 请选择 --------',
          city: '------- 请选择 -------',
          area: '------- 请选择 -------'
        },
        bpChoose: false, // 营业执照证件列表
        lpChoose: false, // 经营许可证件列表
        opChoose: false, // 其他证件列表
        blPicData: {companyId: 0, picName: 'businessLicense'},
        lPicData: {companyId: 0, picName: 'licence'},
        oPicData: {companyId: 0, picName: 'other'},
        industryTypeStr: industryTypes,
        checkedIndustryTypes: [], // 已选择的行业类型（数组）
        type: '',
        company: {
          loginName: '', // 用户名
          userName: '', // 姓名
          password: '', // 密码
          surePassword: '', // 确认密码
          phone: '', // 手机号
          companyId: 0, // 上传图片专用
          brandName: '', // 企业品牌，唯一
          companyName: '', // 公司名称
          companyType: '',
          industryType: '', // 合作类型
          address: '', // 企业详细地址
          postcode: '', // 邮编
          companyTel: '', // 企业电话
          registeredCapital: '', // 注册资金
          registeredDate: '', // 注册时间
          province: '', // 省
          city: '', // 市
          county: '', // 区/县
          linkMan: '', // 联系人姓名
          linkPhone: '', // 联系人手机
          linkTel: '', // 联系人电话
          linkEmail: '', // 联系人邮箱
          linkQQ: '', // 联系人QQ
          linkWeixin: '', // 联系人微信
          authTime: null, // 授权时间
          longitude: 0, // 经度
          latitude: 0, // 纬度
          legalName: '', // 法人姓名
          legalCardNo: '', // 法人身份证
          legalPhone: '', // 法人联系手机
          businessLicenseNo: '', // 营业执照号
          businessLicensePic: '', // 营业执照证件
          licenceNo: '', // 经营许可证号
          licencePic: '', // 经营许可证图片路径
          otherPic: '', // 其他证明材料图片路径
          bpList: [], // 营业执照证件列表
          lpList: [], // 经营许可证件列表
          opList: [] // 其他证件列表
        },
        registerRule: {
          loginName: [
            {required: true, message: '请输入用户名', trigger: 'blur'},
            {validator: validateLoginName}
          ],
          userName: [
            {required: true, message: '请输入真实姓名', trigger: 'blur'}
          ],
          password: [
            {required: true, message: '请输入密码', trigger: 'blur'},
            {validator: checkPassword}
          ],
          surePassword: [
            {required: true, message: '请输入确认密码', trigger: 'blur'},
            {validator: checkSurePassword}
          ],
          phone: [
            {required: true, message: '请输入手机号', trigger: 'blur'},
            {validator: checkPhone}
          ],
          brandName: [
            {required: true, message: '请输入企业品牌名称', trigger: 'blur'}
          ],
          companyName: [
            {required: true, message: '请输入公司名称', trigger: 'blur'}
          ],
          industryType: [
            {required: true, message: '合作类型至少选择一项', trigger: 'blur'}
          ],
          city: [
            {required: true, message: '请选择企业省市地址', trigger: 'change'}
          ],
          address: [
            {required: true, message: '请输入详细地址', trigger: 'blur'}
          ],
          postcode: [
            {required: true, message: '请输入邮编号码', trigger: 'blur'},
            {validator: checkPostcode}
          ],
          companyTel: [
            {required: true, message: '请输入企业电话', trigger: 'change'},
            {validator: checkCompanyTel}
          ],
          registeredCapital: [
            {required: true, message: '请输入注册资金', trigger: 'blur'}
          ],
          registeredDate: [
            {type: 'date', required: true, message: '请输入注册时间', trigger: 'blur'},
            {type: 'date', required: true, message: '请输入注册时间', trigger: 'change'}
          ],
          linkMan: [
            {required: true, message: '请输入联系人姓名', trigger: 'blur'}
          ],
          linkEmail: [
            {validator: checkEmail, trigger: 'blur'}
          ],
          linkQQ: [
            {validator: checkQQ}
          ],
          linkTel: [
            {validator: checkLinkTel, trigger: 'change'}
          ],
          linkPhone: [
            {required: true, message: '请输入联系人手机', trigger: 'change'},
            {validator: checkPhone}
          ],
          legalName: [
            {required: true, message: '请输入法人姓名', trigger: 'blur'}
          ],
          legalCardNo: [
            {required: true, message: '请输入法人身份证', trigger: 'blur'},
            {validator: checkCardNo}
          ],
          legalPhone: [
            {required: true, message: '请输入法人联系手机', trigger: 'change'},
            {validator: checkPhone}
          ],
          businessLicenseNo: [
            {required: true, message: '请输入营业执照号', trigger: 'blur'},
            {validator: checkBNo}
          ],
          licenceNo: [
            {required: true, message: '请输入经营许可证号', trigger: 'blur'},
            {validator: checkLicenceNo}
          ]
//          bpList: [
//            { type: 'array', required: true, message: '请上传营业执照证件', trigger: 'blur' }
//          ],
//          lpList: [
//            { type: 'array', required: true, message: '请上传经营许可证件', trigger: 'blur' }
//          ]
        }
      }
    },
    methods: {
      // 城市组件选择事件
      citySelected (cities) {
        this.company.province = cities.province
        this.company.city = cities.city
        this.company.county = cities.area
      },
      // 复选框选择事件处理
      handleIndustryTypeChecked (checkedIndustryType) {
        this.company.industryType = ''
        if (checkedIndustryType) {
          for (let i = 0; i < checkedIndustryType.length; i++) {
            this.company.industryType += checkedIndustryType[i] + ','
          }
          this.company.industryType = this.company.industryType.substring(0, this.company.industryType.length - 1)
        }
      },
      // 初始化授权时间
      initAuthTime () {
        let now = new Date()
//        now.setFullYear(now.getFullYear() + 1)
        now.setMonth(now.getMonth() + 1)
        this.company.authTime = now
      },
      syncUpload (opts) {
        let formData = new FormData()
        formData.append('file', opts.file)
        formData.append('companyId', opts.data.companyId)
        formData.append('picName', opts.data.picName)
// ////////////////////引入jquery即可使用
//        $.ajax({
//          url: opts.action,
//          async: false,
//          dataType: 'json',
//          type: 'POST',
//          data: formData,
//          processData: false,
//          contentType: false,
//          success: data => {
//            opts.success(data)
//          },
//          error: err => {
//            opts.error(err)
//          }
//        })

// //////////////////不依赖任何插件
        let xhr = (function () {
          if (window.XMLHttpRequest) {
            return new window.XMLHttpRequest()
          } else {
            return new window.ActiveXObject('Microsoft.XMLHttp')
          }
        })()
        xhr.onreadystatechange = function () {
          if (xhr.readyState === 4) {
            if (xhr.status === 200) {
              opts.onSuccess(xhr.responseText)
            } else {
              opts.onError(xhr.responseText)
            }
          }
        }
        xhr.open('POST', opts.action, false)
//        xhr.setRequestHeader('Content-Type', 'multipart/form-data') // 只能在open后调用 发送multipart/form-data时自动设置
        xhr.send(formData)
      },
      // 营业执照上传change事件
      bChangeFunc (file, fileList) {
        const isLt2M = file.size / 1024 / 1024 < 5
        if (!isLt2M) {
          this.$message.error('上传营业执照大小不能超过 5MB!')
          this.$refs.bpUpload.clearFiles()
          console.log(this.company.bpList)
          return isLt2M
        } else {
          if (fileList.length > 1) {
            fileList.splice(0, 1)
            this.bpChoose = true
          } else if (fileList.length === 0) {
            this.bpChoose = false
          } else {
            this.bpChoose = true
          }
          this.company.bpList[0] = file
        }
      },
      // 营业执照上传成功事件
      businessLicenseNoSuccess (response, file, fileList) {
        var resBody = JSON.parse(this.decode(response))
        if (resBody.res === 0) { // 营业执照上传成功开始上传经营许可证件
          this.company.businessLicensePic = resBody.url
//          this.picData = {companyId: this.company.companyId, picName: 'licence'}
//          this.$refs.licenceNoUpload.submit()
        } else {
          this.$refs.bpUpload.clearFiles()
//          this.company.bpList = fileList
          this.bpChoose = false
          this.company.bpList = []
          this.$message({
            showClose: true,
            message: resBody.errorMsg,
            type: 'error'
          })
        }
      },
      // 营业执照的移除事件
      businessLicenseNoRemove (file, fileList) {
        this.company.bpList = []
        this.bpChoose = false
        this.company.businessLicensePic = ''
      },
      // 经营许可证件上传
      licencePicChange (file, fileList) {
        const isLt2M = file.size / 1024 / 1024 < 5
        if (!isLt2M) {
          this.$message.error('上传经营许可证件大小不能超过 5MB!')
          this.$refs.licenceNoUpload.clearFiles()
          return isLt2M
        } else {
          if (fileList.length > 1) {
            fileList.splice(0, 1)
            this.lpChoose = true
          } else if (fileList.length === 0) {
            this.lpChoose = false
          } else {
            this.lpChoose = true
          }
          this.company.lpList[0] = file
        }
      },
      licencePicSuccess (response, file, fileList) {
        var resBody = JSON.parse(this.decode(response))
        if (resBody.res === 0) { // 营业执照上传成功开始上传经营许可证件
          this.company.licencePic = resBody.url
//          if (this.opChoose) {
// //            this.picData = {companyId: this.company.companyId, picName: 'other'}
// //            this.$refs.otherUpload.submit()
//          } else {
//            this.registerSuccess()
//          }
        } else {
          this.$refs.licenceNoUpload.clearFiles()
//          this.company.lpList = fileList
          this.lpChoose = false
          this.company.lpList = []
          this.$message({
            showClose: true,
            message: resBody.errorMsg,
            type: 'error'
          })
        }
      },
      licencePicRemove (file, fileList) {
        this.company.lpList = []
        this.lpChoose = false
        this.company.licencePic = ''
      },
      // 其他证件上传
      otherPicChange (file, fileList) {
        const isLt2M = file.size / 1024 / 1024 < 5
        if (!isLt2M) {
          this.$message.error('上传经营许可证件大小不能超过 5MB!')
          this.$refs.otherUpload.clearFiles()
          return isLt2M
        } else {
          if (fileList.length > 1) {
            fileList.splice(0, 1)
            this.opChoose = true
          } else if (fileList.length === 0) {
            this.opChoose = false
          } else {
            this.opChoose = true
          }
          this.company.opList[0] = file
        }
      },
      otherPicSuccess (response, file, fileList) {
        var resBody = JSON.parse(this.decode(response))
        if (resBody.res === 0) { // 营业执照上传成功开始上传经营许可证件
          this.company.otherPic = resBody.url
//          this.registerSuccess()
        } else {
          this.$refs.otherUpload.clearFiles()
//          this.company.opList = fileList
          this.opChoose = false
          this.company.opList = []
          this.$message({
            showClose: true,
            message: resBody.errorMsg,
            type: 'error'
          })
        }
      },
      otherPicRemove (file, fileList) {
        this.company.opList = []
        this.opChoose = false
//        this.company.opList = fileList
        this.company.otherPic = ''
      },
      goRegister () {
        this.$refs.form.validate((valid) => {
          if (valid) {
            if (!this.bpChoose) {
              this.$message({
                showClose: true,
                message: '请选择营业执照证件',
                type: 'error'
              })
              return
            } else {
              if (!this.lpChoose) {
                this.$message({
                  showClose: true,
                  message: '请选择经营许可证证件',
                  type: 'error'
                })
                return
              } else {
                this.publicRegister()
              }
            }
          }
        })
      },
      // 证件上传成功之后更新公司拓展表证件上传路径
      registerSuccess () {
        var params = {
          businessLicensePic: this.company.businessLicensePic,
          licencePic: this.company.licencePic,
          otherPic: this.company.otherPic,
          companyId: this.company.companyId
        }
        this.$http.post('/smartLight/web/baseCompanyExtend/updateCompanyExtend.htm', params).then(response => {
          this.subRegisterLoading = false
          var resBody = response.body
          if (resBody.isSuccess === 0) { // 营业执照上传成功开始上传经营许可证件
            this.$alert('注册成功等待审核', ' ', {
              type: 'success'
            }).then(() => {
              this.$router.push({path: '/login'})
            })
          } else {
            this.$message({
              showClose: true,
              message: resBody.errorMsg,
              type: 'error'
            })
          }
        })
      },
      // 时间格式转换
      formatDates (d) {
        var year = d.getFullYear()
        var month = ((d.getMonth() + 1) < 10 ? '0' + (d.getMonth() + 1) : (d.getMonth() + 1))
        var date = (d.getDate() < 10 ? '0' + d.getDate() : d.getDate())
        return year + '-' + month + '-' + date
      },
//      跳转到登录页面
      loginPage () {
        this.$router.push({path: '/login'})
      },
      publicRegister () {
        this.subRegisterLoading = true
//        var time = this.formatDates(this.company.registeredDate)
//        this.company.registeredDate = time // 异常时无法二次提交
        var params = {
          opType: 'register',
          type: this.type,
          register: this.company
        }
// /////////////////////////////////////////////////////////////ajax模拟同步$http
//        this.company.bpList = []
//        this.company.lpList = []
//        this.company.opList = []
//        $.ajax({
//          url: '/tour/web/baseAccount/register.htm',
//          dataType: 'text', // 模拟$http
//          contentType: 'application/json;charset=UTF-8', // 模拟$http
//          type: 'post',
//          async: false,
//          data: this.encrypt(params),
//          success: function (data) {
//            let resBody = JSON.parse(this.decode(data))
//            if (resBody.res === 0) {
//              this.company.companyId = resBody.companyId
//              this.blPicData.companyId = this.company.companyId
//              this.lPicData.companyId = this.company.companyId
//              this.oPicData.companyId = this.company.companyId
// //            this.$refs.bpUpload.submit()
//            } else {
//              this.$message({
//                showClose: true,
//                message: resBody.errorMsg,
//                type: 'error'
//              })
//            }
//          }
//        })
        this.$http.post('/smartLight/web/baseCompany/save.htm', params).then(response => {
          var resBody = response.body
          if (resBody.isSuccess === 0) {
            this.company.companyId = resBody.result
            this.blPicData.companyId = resBody.result
            this.lPicData.companyId = resBody.result
            this.oPicData.companyId = resBody.result
 //            this.$refs.bpUpload.submit()
            this.$refs.bpUpload.submit()
            this.$refs.licenceNoUpload.submit()
            if (this.company.opList[0] && this.company.opList[0].url.indexOf('blob:http://') > -1) this.$refs.otherUpload.submit()
            this.registerSuccess()
          } else {
            this.$message({
              showClose: true,
              message: resBody.errorMsg,
              type: 'error'
            })
          }
        })
      }
    },
    mounted () {
      this.type = sessionStorage.getItem('type')
      if (this.type === null || this.type === '') {
        this.$router.push({path: '/login'})
      }
      if (this.type === 1 || this.type === '1') {
        this.company.companyType = 'eb'
      } else if (this.type === 2 || this.type === '2') {
        this.company.companyType = 'md'
      }
      this.initAuthTime()
    },
    components: {
      KtDistpicker, VDistpicker, $
    }
  }

</script>
<style lang="stylus" rel="stylesheet/stylus">
body
  background-color:#f7f7f7;
.bt_t
  color:#48576A;
  font-size:16px;
  border-left:3px solid #20A0FF;padding-left:4px;
  margin-bottom:20px;
#width200
  .el-form-item__content
    width:280px
.loginbtn
  width:80px;text-align:center;border:1px solid #20A0FF;display:inline-block;
  border-radius:2px;float:right;line-height:30px;cursor:pointer;color:#20A0FF;
.loginbtn:hover
  background-color:#f0f0f0;
</style>
